package com.bangdream.michelia.view.adapter;



import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import com.bangdream.michelia.R;
import com.bangdream.michelia.entity.TrainPlanBean;
import com.bangdream.michelia.entity.TrainPlanDetail;
import com.bangdream.michelia.utils.ImageLoadUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.nanchen.compresshelper.StringUtil;

/**
 * Created by zhouyi on 2018/3/25.
 */

public class TrainPlanDetailAdapter extends BaseQuickAdapter<TrainPlanDetail.TrainingPlanBean.PlanItemListBean,BaseViewHolder> {
    public TrainPlanDetailAdapter(int layoutResId) {
        super(layoutResId);
    }
    private Drawable selectBg,selectedBg;
    private int selectTextColor,selectedTextColor;

    @Override
    protected void convert(BaseViewHolder helper, TrainPlanDetail.TrainingPlanBean.PlanItemListBean item) {

        ImageLoadUtils.ImageLoad(mContext,item.getCoverUrl(),(ImageView) helper.getView(R.id.ivIcon),-1);

        helper.setText(R.id.tvTitle,item.getName());

        if(getData().size()==1){
            helper.setVisible(R.id.view_down,false);
            helper.setVisible(R.id.iv_circle,false);
            helper.setVisible(R.id.view_top,false);
        }else{
            if(helper.getAdapterPosition()==0){
                helper.setVisible(R.id.view_top,false);
            }else{
                helper.setVisible(R.id.view_top,true);
            }
            if(helper.getAdapterPosition()==(getData().size()-1)){
                helper.setVisible(R.id.view_down,false);
            }else {
                helper.setVisible(R.id.view_down,true);
            }
        }

        String type = item.getType();
        if(type!=null && type.equals("01")){
            //examId就是判断有没有做过试卷 通过了result=pass  没有通过就没有result不等于pass或者没有这个字段
            String itemId = item.getExamId();
            String itemResult = item.getResult();

            //还没做
            if(StringUtil.isEmpty(itemId)){
                helper.setVisible(R.id.btn1,false);
            }
            //通过了
            else if(!StringUtil.isEmpty(itemId) && !StringUtil.isEmpty(itemResult) && itemResult.equals("pass")){
                helper.setVisible(R.id.btn1,false);
            }
            //没通过
            else if(StringUtil.isEmpty(itemResult) || !itemResult.equals("pass")) {
                helper.setVisible(R.id.btn1,true);
                helper.addOnClickListener(R.id.btn1);
            }
        }
    }
}
